<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>模型管理</title>
  <link rel="stylesheet" href="../../../static/css/layui.css" th:href="@{/css/layui.css}" media="all" />
  <link rel="stylesheet" href="../../../static/css/style.css" th:href="@{/css/style.css}" />
  <link rel="stylesheet" href="../../../static/ajax/libs/select2/select2.min.css"
    th:href="@{/ajax/libs/select2/select2.min.css}" />
  <link rel="stylesheet" href="../../../static/ajax/libs/select2/select2-bootstrap.min.css"
    th:href="@{/ajax/libs/select2/select2-bootstrap.min.css}" />
  <link rel="stylesheet" href="../../../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" />
  <link rel="stylesheet" href="../../../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" />
  <!-- <link rel="stylesheet" href="../../../static/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css"
    th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" /> -->
  <link rel="stylesheet" href="../../../static/ajax/libs/jquery-layout/jquery.layout-latest.css"
    th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" />
  <link rel="stylesheet" href="../../../static/ajax/libs/bootstrap-table/bootstrap-table.min.css"
    th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" />
  <link rel="stylesheet" href="../../../static/ruoyi/css/ry-ui.css" th:href="@{/ruoyi/css/ry-ui.css}" />
  <link rel="stylesheet" href="../../../static/css/add.css" th:href="@{/css/add.css}" />
  <th:block th:include="include :: layout-latest-css" />
  <th:block th:include="include :: ztree-css" />

  <!-- 工作树样式 -->
  <style type="text/css">
    * {
      margin: 0;
      padding: 0;
      list-style: none;
      font-size: 13px;
    }

    #container {
      /* width: 300px; */
      height: auto;
      /* border: 1px solid #e4e4e4; */
      text-align: center;
      margin-right: auto;
      margin-left: auto;
      margin-top: 50px;
      padding: 10px;
    }

    .second-wrapper {
      margin: 10px 0 10px 20px;
      display: none;
    }

    .three-wrapper {
      margin: 10px 0 10px 20px;
      display: none;
    }

    .active {
      background: #ddecfa;
      color: #1c93ec;
    }

    .second-active {
      background-color: #f3f3f3;
      color: #5894bf;
    }

    .search {
      position: absolute;
      right: 20px;
      top: 7px;
      width: 25px;
      height: 25px;
    }

    .main-content {
      width: 500px;
      height: 325px;
      margin: auto;
    }

    .layui-tree-txt {
      font-size: 16px;
    }

    .clickColor {
      color: blue;
    }

    .layui-tree-entry {
      height: 23px;
    }

    .tab {
      width: 100%;
      height: 56px;
      background-color: white;
      border-radius: 5px;
      margin-bottom: 10px;
    }

    .tablebox {
      padding: 10px;
      box-sizing: border-box;
      height: 100%;
    }

    .navbar {
      height: 40px;
    }

    /* 左侧树修改样式 */
    .layui-tree-iconClick .layui-icon {
      font-size: 12px;
      position: absolute;
      top: -1px;
      left: -1px;
    }

    .layui-tree-icon,
    .layui-tree-iconClick {
      position: relative;
      margin-right: 20px;
    }

    .layui-icon-subtraction:after {
      position: absolute;
      top: -1px;
      left: 15px;
      content: "";
      width: 14px;
      height: 13px;
      background-image: url("/ajax/libs/jquery-ztree/3.5/css/metro/img/metro.png");
      background-position: -151px -25px;
    }

    .layui-icon-addition:after {
      position: absolute;
      top: -1px;
      left: 15px;
      content: "";
      width: 14px;
      height: 13px;
      background-image: url("/ajax/libs/jquery-ztree/3.5/css/metro/img/metro.png");
      background-position: -151px -4px;
    }

    .layui-icon-file:before {
      content: "";
      position: absolute;
      top: 4px;
      left: 2px;
      content: "";
      width: 14px;
      height: 13px;
      background-image: url("/ajax/libs/jquery-ztree/3.5/css/metro/img/metro.png");
      background-position: -151px -47px;
    }

    .layui-tree-entry {
      height: 25px !important;
    }

    .layui-tree-txt {
      font-size: 13px;
    }

    .layui-row {
      padding: 10px 0;
    }

    .btn-success {
      margin-left: 10px;
      background-color: #1c84c6;
      border-color: #1c84c6;
    }

    .lay-btn {
      background-color: #1ab394;
      border: #1ab394;
    }
  </style>
</head>

<body>
  <div class="bx container-fluid">
    <!-- 导航 -->
    <div class="layui-row" style="display: flex">
      <!-- 树结构 -->
      <div class="layui-col-md4" style="width: 230px; height: 100%">
        <div class="layui-panel" style="border-radius: 5px">
          <div style="padding: 10px">
            <div id="test1" class="demo-tree-more"
              style="min-height: calc(100vh - 66px);height: 500px;margin-left: 15px; margin-top: 15px;overflow: auto">
            </div>
          </div>
        </div>
      </div>
      <div class="layui-col-xs10" style="flex: 1; margin-left: 10px">
        <div class="grid-demo">
          <!-- 标题新增 -->
          <!-- 导航栏 -->
          <div class="tab">
            <div class="layui-row">
              <div class="layui-col-xs7">
                <div class="grid-demo grid-demo-bg1" id="add" style="visibility: hidden">
                  <a class="btn btn-success" href="#" data-toggle="modal" data-target="#myModal">
                    <i class="fa fa-plus"></i> 添加模型
                  </a>
                  <!-- <a
                      
                      style="
                        font-weight: 700;
                        font-size: 16px;
                        line-height: 40px;
                        padding-left: 10px;
                      "
                    >
                    <i class="fa fa-plus"></i>
                      <span>添加模型</span>
                    </a> -->
                </div>
              </div>
              <div class="layui-col-xs5">
                <div class="grid-demo">
                  <div class="layui-input-block" style="position: absolute; right: 70px; display: flex">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入内容"
                      class="layui-input" style="width: 250px" id="searchList" />
                    <button type="button" class="layui-btn layui-btn-primary"
                      style="flex: 1;background-color: #1ab394;border-color: #1ab394; color: white;" id="search">
                      <i class="fa fa-search"></i>&nbsp;搜索
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- 表格 -->
          <div class="tablebox tab">
            <table id="table" lay-filter="test"></table>
            <div id="pages" style="margin-left: 30%;"></div>
            <script type="text/html" id="zt">
                {{# if(d.status == 0){ }} 未发布 {{# } }} {{# if(d.status != 0){
                }} 已发布 {{# } }}
              </script>
            <script type="text/html" id="toolEventDemo">
                <a class="layui-btn layui-btn-xs" id="add" lay-event="add"
                  ><i class="fa fa-gear"></i> 模型设计</a
                >
                {{# if(d.status == 0){ }}
                <a
                  class="layui-btn layui-btn-xs layui-btn-normal"
                  lay-event="release"
                  ><i class="fa fa-refresh"></i> 发布</a
                >
                {{# } }} {{# if(d.status == 1){ }}
                <a
                  class="layui-btn layui-btn-xs layui-btn-normal"
                  lay-event="release"
                  ><i class="fa fa-refresh"></i>取消发布</a
                >
                {{# } }}
                <a class="layui-btn layui-btn-xs layui-btn-warm copy"
                lay-event="copy">
			            <i class="fa fa-edit"></i> 复制
			        </a>
                <a class="layui-btn layui-btn-xs layui-btn-danger delete"
                lay-event="delete">
			            <i class="fa fa-remove"></i> 删除
			        </a>
              {{# if(d.shareStatus == 0){ }}
                <a class="layui-btn layui-btn-xs layui-btn-normal share"
                lay-event="share">
			            <i class="fa fa-share"></i> 分享
			        </a>
              {{# } }} {{# if(d.shareStatus == 1){ }}
              <a class="layui-btn layui-btn-xs layui-btn-normal share"
                lay-event="share">
			            <i class="fa fa-share"></i> 已分享
			        </a>
              {{# } }}
              </script>
          </div>

        </div>
      </div>
    </div>
    <!-- body -->
    <!-- Modal 设备管理模态框 -->
    <!-- Modal -->
    <div class="modal fade main-equipment" id="myModal-equipment" tabindex="-1" role="dialog"
      aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="myContent">
          <div class="title">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">x</span>
            </button>
            <h4 class="titleText" id="myModalLabel">添加设备</h4>
          </div>
          <div class="myBody">
            <input type="text" placeholder="请输入内容" /><span class="mySpan glyphicon glyphicon-search"></span>
          </div>
          <div class="myFooter">
            <button type="button">确 定</button>
          </div>
        </div>
      </div>
    </div>
    <!-- Modal 新增弹层模态框 -->
    <div class="main-content modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <form class="layui-form" action="" lay-filter="example">
        <h4>基本信息</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true"><i class="layui-icon layui-icon-close-fill" style="font-size: 20px"></i>
          </span>
        </button>
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">区域信息</label>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">模型名称</label>
          <div class="layui-input-inline">
            <input type="text" name="templateName" id="text" required lay-verify="required" placeholder="请输入名称"
              autocomplete="off" class="layui-input" />
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">所属场景</label>
          <div class="layui-input-inline">
            <input type="text" name="scene" required lay-verify="required" placeholder="请选择上级区域组" autocomplete="off"
              class="layui-input" disabled />
          </div>
        </div>
      </form>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button type="button" class="layui-btn btn btn-sm btn-primary" lay-submit lay-filter="formDemo"
            id="LAY-component-form-getval" aria-label="Close" data-dismiss="modal"><i
              class="fa fa-check"></i>保存</button>&nbsp;
          <button type="button" class="layui-btn btn btn-sm btn-danger" data-dismiss="modal" aria-label="Close"><i
              class="fa fa-reply-all"></i>关闭</button>
        </div>
      </div>
    </div>

    <!-- 复制的弹出层 -->
    <!-- 遮罩层 -->
    <div class="wrapperBox" data-type="rt" style="display: none">
      <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <div class="addShebei">
          <span>设备信息</span>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">模型名称</label>
          <div class="layui-input-block">
            <input type="text" value="" name="title" required lay-verify="required" placeholder="请输入名称"
              autocomplete="off" id="modelName" class="layui-input" />
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">场景名称</label>
          <div class="layui-input-block">
            <input type="text" name="scene2" required lay-verify="required" autocomplete="off" class="layui-input"
              disabled />
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button type="button" class="layui-btn btn btn-sm btn-primary" id="submit"><i
                class="fa fa-check"></i>立即提交</button>&nbsp;
            <button type="button" class="layui-btn btn btn-sm btn-danger" id="Reset"><i
                class="fa fa-reply-all"></i>重置</button>
          </div>
        </div>
      </div>
    </div>
    <!-- 分享 -->
  </div>
  <script src="../../../static/js/jquery.min.js"></script>
  <script src="../../../static/js/bootstrap.min.js"></script>
  <script src="../../../static/ajax/libs//layui/layui.min.js"></script>
  <!-- <script src="../../../static/js/template/layui.js" th:src="@{/js/template/layui.js"></script> -->
  <!-- <script src="../../../static/ajax/libs/layer/layer.min.js" ths:src="/ajax/libs/layer/layui.min.js"></script> -->
  <script src="../../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
  <script src="../../../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>
  <script src="../../../static/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js"
    th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
  <script src="../../../static/ajax/libs/jquery-layout/jquery.layout-latest.js"
    th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>

  <!-- <script src="../../../static/js/layui.js"></script> -->
  <!-- bootstrap-table 表格插件 -->
  <!-- <script src="../../../static/ajax/libs/bootstrap-table/bootstrap-table.min.js"
    th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
  <script src="../../../static/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"
    th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
  <script src="../../../static/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js"
    th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js}"></script> -->
  <!-- jquery-validate 表单验证插件 -->
  <!-- <script src="../../../static/ajax/libs/validate/jquery.validate.min.js"
    th:src="@{/ajax/libs/validate/jquery.validate.min.js}"></script>
  <script src="../../../static/ajax/libs/validate/jquery.validate.extend.js"
    th:src="@{/ajax/libs/validate/jquery.validate.extend.js}"></script>
  <script src="../../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script> -->
  <!-- bootstrap-table 表格树插件
  <script src="../../../static/ajax/libs/bootstrap-table/extensions/tree/bootstrap-table-tree.min.js"
    th:src="@{/ajax/libs/bootstrap-table/extensions/tree/bootstrap-table-tree.min.js}"></script> -->
  <!-- 遮罩层 -->

  <script src="../../../static/ajax/libs/blockUI/jquery.blockUI.js"
    th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
  <script src="../../../static/ajax/libs/iCheck/icheck.min.js" th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
  <script src="../../../static/ajax/libs/layer/layer.min.js" th:src="@{/ajax/libs/layer/layer.min.js}"></script>
  <!-- <script src="../../../static/ajax/libs/layui/layui.min.js" th:src="@{/ajax/libs/layui/layui.min.js}"></script> -->
  <script src="../../../static/ruoyi/js/common.js" th:src="@{/ruoyi/js/common.js}"></script>
  <script src="../../../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui}"></script>
  <script src="https://www.jq22.com/jquery/jquery-1.9.1.js"></script>
  <script src="../../../static/js/layui.js" th:src="@{/js/layui.js}"></script>
  <script th:src="@{/js/layui.js}" src="../../../static/js/layui.js"></script>
  <script th:src="@{/js/treeTable.js}" src="../../../static/js/treeTable.js"></script>
  <!-- <script src="../../../static/js/layui.js" th:src="@{/js/layui.js}"></script> -->
  <script type="text/javascript">
    //添加组和设置组添加类名
    // $(".container-1").on("click", ".btnFn", function () {
    //   $(".btnFn").removeClass("second-active")
    //   $(this).addClass("second-active");
    // })
    // 树形结构
    let pageSize;
    let pageNum;
    let total; //总数
    var page = { pageSize: 10, pageNum: 1 };
    var checkIds = []
    $(function () {
      leftTree();
      $.ajax({
        url: "/youtian/template/list",
        dataType: "json",
        // type:'GET',
        type: "post",
        headers: { "Content-Type": "application/x-www-form-urlencoded" },
        data: page,
        success: function (res) {
          tableList(res);
        },
      });
    });

    let treeId; //左侧节点id
    let templateId; //当前行表格数据的id
    let nodes; //
    let edges;
    let closeIndex; //关闭复制的弹出层
    let ejdwId;//左侧树二级id
    let dw_3_id; //左侧树三级id
    let dw_4_id; //左侧树四级id
    let dw_5_id; //左侧树五级id
    //表格
    function tableList(data) {
      // console.log(data);
      let tableData = data.rows;
      total = data.total;
      console.log(total);
      layui.use(["table", 'laypage'], function () {
        var table = layui.table;
        var laypage = layui.laypage;
        table.render({
          elem: "#table",
          height: 430,
          cols: [
            [
              {
                type: "checkbox",
                field: "left",
                title: "序号",
                unresize: true,
                align: "center",
              },
              {
                field: "templateName",
                title: "模型名称",
                unresize: true,
                align: "center",
              },
              {
                field: "deptName",
                title: "所属部门",
                unresize: true,
                align: "center",
              },
              {
                field: "templateId",
                title: "模型id",
                sort: false,
                unresize: true,
                align: "center",
                width:'10%'
              },
              {
                field: "status",
                title: "状态",
                templet: "#zt",
                sort: false,
                unresize: true,
                align: "center",
                width:'15%'
              },
              {
                field: "set",
                title: "操作",
                templet: "#toolEventDemo",
                sort: false,
                unresize: true,
                width: '50%',
                align: "center",
              },
            ],
          ],
          data: tableData,
        });
        // 分页功能
        laypage.render({
          elem: "pages", //注意，这里的 test1 是 ID，不用加 # 号
          count: data.total, //数据总数，从服务端得到
          curr: page.pageNum,
          layout: ["prev", "page", "next", "skip"],
          limit: page.pageSize,
          jump: function (obj, first) {
            //obj包含了当前分页的所有参数，比如：
            console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
            console.log(obj.limit); //得到每页显示的条数
            page.pageSize = obj.limit;
            page.pageNum = obj.curr;
            console.log(page, "page");
            //首次不执行
            if (!first) {
              $.ajax({
                url: "/youtian/template/list",
                dataType: "json",
                // type:'GET',
                type: "post",
                headers: {
                  "Content-Type": "application/x-www-form-urlencoded",
                },
                data: page,
                success: function (res) {
                  tableList(res);
                },
              });
            }
          },
        });

        table.on("tool(test)", function (obj) {
          //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data = obj.data; //获得当前行数据
          layEvent = obj.event; //获得 lay-event 对应的值
          templateId = obj.data.templateId; //当前行的templateId
          owner = obj.data.owner
          console.log(owner, 'owner');
          nodes = obj.data.nodes;
          edges = obj.data.edges;
          // console.log(nodes,edges);
          //复制的弹框
          if (layEvent === "copy") {
            if (!treeId) {
              layer.msg("请选择左侧节点后在进行下一步");
            } else {
              var index = layer.open({
                type: 1, //可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                title: ["复制信息", "font-size:18px;"], //数组第二项可以写任意css样式；如果你不想显示标题栏，你可以title: false
                area: ["500px", "100%"],
                content: $(".wrapperBox"),
                offset: "auto",
                move: false,
                offset: "rt",
                // showCheckbox:true,
                cancel: function (index, layero) { },
              });
              closeIndex = index;
            }
          }
          //跳转到模型设计页面
          if (layEvent === "add") {
            //如果左侧树节点没有选中，则给予提示
            if (!treeId) {
              layer.msg("请选择左侧节点后在进行下一步");
            } else {
              if (!owner) {
                return layer.msg('你不是创建者,不可以跳转模型设计')
              } else {
                window.location.replace(
                  `/page-route/template-edit?templateId=${templateId}&treeId=${treeId}&type=1&owner=${owner}`
                );
              }
              //点击模型设计跳转页面 type=1是表示从模型设计跳转过去的
              // window.location.href = `/youtian/template/edit/index?templateId=${templateId}&treeId=${treeId}&type=1`
              // window.location.href = `/page-route/template-edit?templateId=${templateId}&treeId=${treeId}&type=1`
              // window.location.href = `/page-route/template-edit?templateId=${templateId}&treeId=${treeId}&type=1`

              console.log("跳模型设计", 555225);
            }
          }
          //发布
          if (layEvent === "release") {
            if (!owner) {
              return layer.msg('你不是创建者,不可以发布')
            } else {
              if (data.status == 0) {
                let status = 1;
                layer.confirm(
                  "确定发布吗?",
                  { title: "发布信息" },
                  function (index) {
                    let list = {
                      status: status,
                      templateId: data.templateId,
                    };
                    $.ajax({
                      url: "/youtian/template/updateTemplate",
                      type: "POST",
                      dataType: "json",
                      data: JSON.stringify(list),
                      headers: { "Content-Type": "application/json" },
                      success: function (res) {
                        if (res.code == 0) {
                          let page = { pageSize: total, pageNum: 1 };
                          $.ajax({
                            url: "/youtian/template/list",
                            dataType: "json",
                            // type:'GET',
                            type: "post",
                            headers: {
                              "Content-Type":
                                "application/x-www-form-urlencoded",
                            },
                            data: page,
                            success: function (res) {
                              tableList(res);
                              layer.msg("发布成功");
                            },
                          });
                        }
                        leftTree();
                      },
                    });
                    layer.close(index);
                  }
                );
              } else {
                if (!owner) {
                  return layer.msg('你不是创建者,不可以取消发布')
                } else {
                  let status = 0;
                  layer.confirm(
                    "是否取消发布?",
                    { title: "发布信息" },
                    function (index) {
                      // console.log(index);
                      let list = {
                        status: status,
                        templateId: data.templateId,
                      };
                      // console.log(list);
                      $.ajax({
                        url: "/youtian/template/updateTemplate",
                        type: "POST",
                        dataType: "json",
                        data: JSON.stringify(list),
                        headers: { "Content-Type": "application/json" },
                        success: function (res) {
                          console.log(res);
                          if (res.code == 0) {
                            let page = { pageSize: 999, pageNum: 1 };
                            $.ajax({
                              url: "/youtian/template/list",
                              dataType: "json",
                              // type:'GET',
                              type: "post",
                              headers: {
                                "Content-Type":
                                  "application/x-www-form-urlencoded",
                              },
                              data: page,
                              success: function (res) {
                                tableList(res);
                                layer.msg("取消发布成功");
                              },
                            });
                          }
                          leftTree();
                        },
                      });
                      layer.close(index);
                    }
                  );
                }

              }
            }

          }
          //删除
          if (layEvent === "delete") {
            let list = {
              templateIds: templateId,
            }
            console.log(list, '删除的');
            if (!owner) {
              return layer.msg('你不是创建者,不可以分享')
            } else {
              layer.confirm(
                "确定删除当前数据吗?",
                { title: "删除信息" },
                function (index) {
                  $.ajax({
                    url: `/youtian/template/delete/${templateId}`,
                    type: 'POST',
                    dataType: "json",
                    // data: JSON.stringify(list),
                    headers: { "Content-Type": "application/json" },
                    success: function (res) {
                      console.log(res, '删除');
                      if (res.code == 0) {
                        let page = { pageSize: 999, pageNum: 1 };
                        $.ajax({
                          url: "/youtian/template/list",
                          dataType: "json",
                          // type:'GET',
                          type: "post",
                          headers: {
                            "Content-Type":
                              "application/x-www-form-urlencoded",
                          },
                          data: page,
                          success: function (res) {
                            tableList(res);
                            layer.msg("删除成功");
                          },
                        });
                      }
                      leftTree();
                    }
                  })
                  layer.close(index);
                }
              );
            }

          }
          //分享
          if (layEvent === 'share') {
            if (!owner) {
              return layer.msg('你不是创建者,不可以分享')
            } else {
              if (data.shareStatus == 0) {
                let list = {
                  "templateId": templateId,
                  "shareStatus": 1
                }
                layer.confirm(
                  "是否分享当前信息?",
                  { title: "分享信息" },
                  function (index) {
                    $.ajax({
                      url: '/youtian/template/shareTemplate',
                      type: 'POST',
                      dataType: "json",
                      data: JSON.stringify(list),
                      headers: { "Content-Type": "application/json" },
                      success: function (res) {
                        console.log(res, '分享');
                        if (res.code == 0) {
                          let page = { pageSize: 999, pageNum: 1 };
                          $.ajax({
                            url: "/youtian/template/list",
                            dataType: "json",
                            // type:'GET',
                            type: "post",
                            headers: {
                              "Content-Type":
                                "application/x-www-form-urlencoded",
                            },
                            data: page,
                            success: function (res) {
                              tableList(res);
                              layer.msg("分享成功");
                            },
                          });
                        }
                        leftTree();
                      }
                    })
                    layer.close(index);
                  }
                );
              } else {
                if (!owner) {
                  return layer.msg('你不是此条数据创建者,不可以取消')
                } else {
                  let list = {
                    "templateId": templateId,
                    "shareStatus": 0
                  }
                  layer.confirm(
                    "是否取消分享当前信息?",
                    { title: "取消分享" },
                    function (index) {
                      $.ajax({
                        url: '/youtian/template/shareTemplate',
                        type: 'POST',
                        dataType: "json",
                        data: JSON.stringify(list),
                        headers: { "Content-Type": "application/json" },
                        success: function (res) {
                          console.log(res, '分享');
                          if (res.code == 0) {
                            let page = { pageSize: 999, pageNum: 1 };
                            $.ajax({
                              url: "/youtian/template/list",
                              dataType: "json",
                              // type:'GET',
                              type: "post",
                              headers: {
                                "Content-Type":
                                  "application/x-www-form-urlencoded",
                              },
                              data: page,
                              success: function (res) {
                                tableList(res);
                                layer.msg("取消分享成功");
                              },
                            });
                          }
                          leftTree();
                        }
                      })
                      layer.close(index);
                    }
                  );
                }

              }
            }


          }
        });
      });
    }
    //树形控件
    function createTree(dom) {
      layui.use("tree", function () {
        var tree = layui.tree;
        var treeCkData = { id: 0 };
        $.ajax({
          url: "/youtian/scene-category/since-dept-tree-new",
          type: "POST",
          dataType: "json",
          success: function (res) {
            tree.render({
              elem: dom,
              data: res.data,
              // showCheckbox:true,
              click: function (obj) {
                console.log(obj);
                if (obj.data.level == 1) {
                  ejdwId = obj.data.id
                  var data = {
                    ejdwId: ejdwId,
                    pageSize: 99999,
                    pageNum: 1,
                    total: 0,
                  };
                } else if (obj.data.level == 2) {
                  ejdwId = obj.data.id
                  var data = {
                    ejdwId: ejdwId,
                    pageSize: 99999,
                    pageNum: 1,
                    total: 0,
                  };
                } else if (obj.data.level == 3) {
                  dw_3_id = obj.data.id
                  var data = {
                    dw_3_id: dw_3_id,
                    pageSize: 99999,
                    pageNum: 1,
                    total: 0,
                  };
                } else if (obj.data.level == 4) {
                  dw_4_id = obj.data.id
                  var data = {
                    dw_4_id: dw_4_id,
                    pageSize: 99999,
                    pageNum: 1,
                    total: 0,
                  };
                } else if (obj.data.level == 5) {
                  dw_5_id = obj.data.id
                  var data = {
                    dw_5_id: dw_5_id,
                    pageSize: 99999,
                    pageNum: 1,
                    total: 0,
                  };
                } else if (obj.data.label == "scene") {
                  treeId = obj.data.id
                  var data = {
                    sceneId: treeId,
                    pageSize: 99999,
                    pageNum: 1,
                    total: 0,
                  };
                }
                console.log(ejdwId, '一级二级id');
                console.log(dw_3_id, '三级id');
                console.log(dw_4_id, '四级id');
                console.log(dw_5_id, '五级id');
                console.log(treeId, '五级之后的id');
                // 点击左侧工作树高亮显示
                $('div[data-id="' + treeCkData.id + '"] span')
                  .eq(1)
                  .last()
                  .removeClass("clickColor");
                $('div[data-id="' + obj.data.id + '"] span')
                  .eq(1)
                  .last()
                  .addClass("clickColor");

                treeCkData = obj.data;
                treeId = obj.data.id;

                $.ajax({
                  url: "/youtian/template/list",
                  dataType: "json",
                  // type:'GET',
                  type: "post",
                  headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                  },
                  data: data,
                  success: function (res) {
                    console.log(res.total, total);
                    tableList(res);
                  },
                });
                if (obj.data.label == 'scene') {
                  $("#add").css("visibility", "visible");
                  $(".copy").css("visibility", "visible");
                } else {
                  $("#add").css("visibility", "hidden");
                  $(".copy").css("visibility", "hidden");
                }
                let label = obj.data.title;
                $('input[name="scene"]').val(label);
                $('input[name="scene2"]').val(label);
              },
              // oncheck: function(obj){
              //   console.log(obj.data); // 得到当前点击的节点数据
              //   console.log(obj.checked); // 节点是否被选中
              //   console.log(obj.elem); // 得到当前节点元素
              // }
            });
          },
        });
      });
    }

    //重置
    $("#Reset").on("click", function () {
      $("#modelName").val("");
    });
    function leftTree() {
      createTree("#test1");
    }
    //复制
    $("#submit").on("click", function () {
      var inp = $("#modelName").val();
      // console.log(closeIndex);
      if (inp == "") {
        return layer.msg("模型名称不能为空");
      }
      $.ajax({
        url: "/youtian/template/copyTemplate",
        method: "POST",
        headers: { "Content-Type": "application/json" },
        data: JSON.stringify({
          sceneId: treeId,
          templateName: inp,
          templateId: templateId,
          nodes: nodes,
          edges: edges,
        }),
        success: function (res) {
          layer.close(closeIndex);
          layer.msg(res.msg);
          // console.log(res);
          if (res.code == 0) {
            let page = { pageSize: 99999, pageNum: 1 };
            $.ajax({
              url: "/youtian/template/list",
              dataType: "json",
              // type:'GET',
              type: "post",
              headers: {
                "Content-Type": "application/x-www-form-urlencoded",
              },
              data: page,
              success: function (res) {
                tableList(res);
              },
            });
          }
        },
      });
    });
    //分享取消
    $("#cancel").on('click', function () {
      layer.close(closeIndex);
    })
    //分享确定
    $("#determine").on('click', function () {
      console.log(checkIds);
      let list = {
        sceneId: treeId,
        templateIds: templateId,
        ids: checkIds
      }
      console.log(list);
    })
    //新增
    $("#LAY-component-form-getval").on("click", function () {
      if ($('input[name="templateName"]').val() == "") {
        return layer.msg("模型名称不能为空");
      }
      $.ajax({
        url: "/youtian/template/saveTemplate",
        method: "POST",
        dataType: "json",
        headers: { "Content-Type": "application/json" },
        data: JSON.stringify({
          sceneId: treeId,
          templateName: $('input[name="templateName"]').val(),
        }),
        success: function (res) {
          console.log(res);
          // aria-label="Close"
          // data-dismiss="modal"
          // $('#LAY-component-form-getval').css({'aria-label':'Close','data-dismiss':'modal'})
          // $('#LAY-component-form-getval').replaceWith('<button class="layui-btn" lay-submit lay-filter="formDemo" id="LAY-component-form-getval" aria-label="Close" data-dismiss="modal">保存</button>')
          $('input[name="templateName"]').val("");
          layer.msg("添加成功");
          if (res.code == 0) {
            let page = { pageSize: 99999, pageNum: 1, sceneId: treeId };
            $.ajax({
              url: "/youtian/template/list",
              dataType: "json",
              // type:'GET',
              type: "post",
              headers: {
                "Content-Type": "application/x-www-form-urlencoded",
              },
              data: page,
              success: function (res) {
                tableList(res);
              },
            });
          }
        },
      });
    });

    //模糊搜索
    $("#search").on("click", function () {
      let val = $("#searchList").val();
      console.log(val);
      let page = { pageSize: 99999, pageNum: 1, templateName: val };
      $.ajax({
        url: "/youtian/template/list",
        dataType: "json",
        // type:'GET',
        type: "post",
        headers: { "Content-Type": "application/x-www-form-urlencoded" },
        data: page,
        success: function (res) {
          tableList(res);
        },
      });
    });
  </script>
</body>

</html>